/**
 * 文件名称 : AccelerometerHandler.java
 * <p>
 * 作者信息 : maidou
 * <p>
 * 创建时间 : 2011-8-4, 上午3:18:38
 * <p>
 * 版权声明 : Copyright (c) 2009-2012 CIeNET Ltd. All rights reserved
 * <p>
 * 评审记录 :
 * <p>
 */

package com.ttomato.game.framework.impl;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

/**
 * 请在这里增加文件描述
 * <p>
 */
public class AccelerometerHandler implements SensorEventListener
{
    float mAccelX;
    
    float mAccelY;
    
    float mAccelZ;
    
    public AccelerometerHandler(Context context)
    {
        SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        
        if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() != 0)
        {
            Sensor accelerometerSensor = manager.getSensorList(Sensor.TYPE_ACCELEROMETER)
                    .get(0);
            
            manager.registerListener(this,
                    accelerometerSensor,
                    SensorManager.SENSOR_DELAY_GAME);
        }
    }
    
    
    public void onAccuracyChanged(Sensor sensor, int accuracy)
    {
        // TODO Auto-generated method stub
        
    }
    
    
    public void onSensorChanged(SensorEvent event)
    {
        // TODO Auto-generated method stub
        mAccelX = event.values[0];
        mAccelY = event.values[1];
        mAccelZ = event.values[2];
    }
    
    public float getAccelX()
    {
        return mAccelX;
    }
    
    public float getAccelY()
    {
        return mAccelY;
    }
    
    public float getAccelZ()
    {
        return mAccelZ;
    }
    
}
